home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / prog / plane / pset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.6 KB  |  117 lines

  1. #include <LEDA/point_set.h>
  2.  
  3.  
  4.  
  5.  
  6. main()
  7. {
  8.  
  9.   point_set<string> S;
  10.  
  11.   list<ps_item> L;
  12.   ps_item       it=nil;
  13.   point         p; 
  14.   char          ch;
  15.  
  16.  
  17.  
  18.   while (ch != 'q')
  19.   { 
  20.     cout << "(r/s/f/n/i/d/D/l/q): ";
  21.     cin  >> ch;
  22.  
  23.     float T  = used_time();
  24.      
  25.     switch(ch) {
  26.  
  27.     case 'i':  { cout << "insert point: ";
  28.                  cin >> p;
  29.                  S.insert(p,string("x = %f",p.xcoord()));
  30.                  break;
  31.                 }
  32.  
  33.      case 'n': { cout << "nearest neighbor: ";
  34.              cin >> p;
  35.                  it = S.nearest_neighbor(p);
  36.                  if (it!=nil) cout << S.key(it);
  37.                  else cout << "Empty point set.\n";    
  38.                  newline;
  39.                  break;
  40.                }
  41.  
  42.  
  43.     case 'r' : { init_random();
  44.                  int n = read_int("#random points = ");
  45.                  while (n--)
  46.                  { double x = random(1,1000)/100.0;
  47.                    double y = random(1,1000)/100.0;
  48.                    S.insert(point(x,y),string("x = %f",x));
  49.                   }
  50.                  cout << string("time: %6.2f\n",used_time(T));
  51.                  break;
  52.                 }
  53.  
  54.     case 's': { double a=read_real("x0=");
  55.                 double b=read_real("x1=");
  56.                 double c=read_real("y0=");
  57.                 double d=read_real("y1=");
  58.   
  59.                 L = S.range_search(a,b,c,d);
  60.   
  61.                 forall(it,L) cout << S.key(it) << " " << S.inf(it) << "\n";
  62.                 newline;
  63.               
  64.                 cout << string("time: %6.2f\n",used_time(T));
  65.                 break;
  66.               }
  67.  
  68.  
  69.     case 'd': { cout << "delete point: ";
  70.             cin >> p;
  71.                 S.del(p);
  72.                 break;
  73.                }
  74.  
  75.     case 'D': { double a=read_real("x0=");
  76.                 double b=read_real("x1=");
  77.                 double c=read_real("y0=");
  78.                 double d=read_real("y1=");
  79.   
  80.                 L = S.range_search(a,b,c,d);
  81.   
  82.                 forall(it,L) 
  83.                 { point p = S.key(it);
  84.                   cout << "delete: " << p <<"\n";
  85.                   S.del(p);
  86.                  }
  87.                 newline;
  88.               
  89.                 cout << string("time: %6.2f\n",used_time(T));
  90.                 break;
  91.               }
  92.  
  93.  
  94.     case 'f': { cout << "find point: ";
  95.             cin >> p;
  96.                 if (S.lookup(p) != nil) cout << "yes";
  97.                 else cout << "no";
  98.                 newline;
  99.                 break;
  100.                }
  101.  
  102.  
  103.     case 'l': { L = S.all_items();
  104.                 forall(it,L) 
  105.                   cout << S.key(it) << " " << S.inf(it) << "\n";
  106.                 newline;
  107.                 break;
  108.                }
  109.  
  110.  
  111.     } //switch
  112.  
  113.   } //for
  114.  
  115.   return 0;
  116. }
  117.